package services;

import dao.*;
import dao.imp.*;
import entity.Dept;
import entity.Employee;

/**
 * @program: personnel_management_system
 * @description: dml
 * @author: Mr.Sun
 * @create: 2020-06-09 12:11
 **/

public class DMLService {
    public boolean DMLExecute(String type,String tableName ,Object obj) throws Exception {
        boolean res = false;
        switch (tableName){
            case "Employee":
                IEmployeeDao dao = new EmployeeDao();
                res = sqlType(dao,type,obj);
                break;
            case "Dept":
                IDeptDao dao1 = new DeptDao();
                res = sqlType(dao1,type,obj);
                break;
            case "Contract":
                IContractDao dao2 = new ContractDao();
                res = sqlType(dao2,type,obj);
                break;
            case "Train":
                ITrainDao dao3 = new TrainDao();
                res = sqlType(dao3,type,obj);
                break;
            case "Rewards":
                IRewardsDao dao4 = new RewardsDao();
                res = sqlType(dao4,type,obj);
                break;
            case "Job":
                IJobDao dao5 = new JobDao();
                res = sqlType(dao5,type,obj);
                break;
            case "Titles":
                ITitlesDao dao6 = new TitlesDao();
                res = sqlType(dao6,type,obj);
                break;
        }
        return res;
    }

    public boolean sqlType(IDmlSqlDao dao , String type ,Object obj){
        boolean res = false;
        switch (type){
            case "insert":
                res = dao.insert(obj);
                break;
            case "update":
                System.out.println("update"+obj);
                res = dao.update(obj);
                break;
            case "delete":
                res = dao.delete(obj);
                break;
        }
        return res ;
    }
}
